#include <fstream>
#include "Newton.h"
#include <iostream>
#include <string>
//#include <mat.h>
using namespace std;

int main()
{


  double n;
  for (n=2;n<=8;n=n+2)
    {
      vector<double> x;
      vector<double> y;
      for(int i=0;i<=n;i++){
      x.push_back(10);
      y.push_back(10);
 }
 
  for (int i=0;i<=n;i++)
    {
      x[i]=-5+10*(i/n);
    }
  for (int i=0;i<=n;i++)
    {
      y[i]=1/(1+x[i]*x[i]);
    }

 Newton problem_b(x,y);
 cout<<"When N equals "<<n<<":"<<endl;
 for(int i=0;i<x.size();i++){
   cout<<"x^("<<n-i<<"): "<<problem_b.answer[i]<<endl;
 }
    

 
    ofstream p_B;
    if(n==2) p_B.open("p_B.txt", std::ios::out);
    else p_B.open("p_B.txt", std::ios::out | std::ios::app);  //以写入和在文件末尾添加的方式打开.txt文件，没有的话就创建该文件。
       if (!p_B.is_open())
        return 0;
            for(int i=0;i<x.size();i++)
	      {
               p_B<< problem_b.answer[i] <<endl;
              }

	      p_B.close();
    }
}


